<template>
  <div>
    <!--面包屑组件-->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>权限管理</el-breadcrumb-item>
      <el-breadcrumb-item>权限列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!--卡片组件-->
    <el-card class="card-box">
      <!--表格组件-->
      <el-table stripe border :data="rightsList">
        <el-table-column label="#" type="index"></el-table-column>
        <el-table-column label="权限名称" prop="authName"></el-table-column>
        <el-table-column label="路径" prop="path"></el-table-column>
        <el-table-column label="权限等级">
          <template slot-scope="scope">
            <!--Tag组件-->
            <!--type属性指定标签的样式类型-->
            <!--也可将可能要展示的标签全都写出来，再使用v-if="scope.row.level === '0'"判断是否渲染-->
            <el-tag :type="rightsLevelTag[scope.row.level].type">{{
              rightsLevelTag[scope.row.level].content
            }}</el-tag>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
export default {
  name: "rights",
  data() {
    return {
      rightsList: [],
      rightsLevelTag: {
        0: { type: "", content: "一级" },
        1: { type: "success", content: "二级" },
        2: { type: "warning", content: "三级" }
      }
    };
  },
  created() {
    this.getRightsList();
  },
  methods: {
    async getRightsList() {
      const { data: res } = await this.$http.get("rights/list");
      if (res.meta.status !== 200)
        return this.$message.error("获取权限列表失败，请重试！");
      this.rightsList = res.data;
    }
  }
};
</script>

<style lang="less" scoped></style>
